<?php
/*
 * Created on Jul 30, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

class MathUtils
{
	
	function avg($array)
	{
		$sum = 0;
		foreach($array as $value){
			$sum += $value;
		}
		
		$lenght = count($array);
		$mean 	= $sum / $lenght;
		
		return $mean;
	}

	/* remove n max data
	 * 
	 */
	function max_avg($array, $n){
		rsort($array);
		for($i=0; $i<$n; $i++){
			unset($array[$i]);	
		}
		$max_mean = mean($array);
		return $max_mean;
	}
	
	/* remove n min data
	 * 
	 */
	function min_avg($array, $n){
		sort($array);
		for($i=0; $i<$n; $i++){
			unset($array[$i]);	
		}
		$min_mean = mean($array);
		return $min_mean;
	}
	
	/* remove n max data and remove m min data
	 * 
	 */
	function max_min_avg($array, $n, $m){
		rsort($array);
		for($i=0; $i<$n; $i++){
			unset($array[$i]);	
		}
		
		sort($array);
		for($i=0; $i<$m; $i++){
			unset($array[$i]);	
		}
		
		$max_min_mean = mean($array);
		return $max_min_mean;
	}
	
	/* remove n max data
	 * 
	 */
	function max_Max($array, $n){
		rsort($array);
		for($i=0; $i<$n; $i++){
			unset($array[$i]);	
		}
		$max_mean = max($array);
		return $max_mean;
	}
	
	/* remove n min data
	 * 
	 */
	function min_Min($array, $n){
		sort($array);
		for($i=0; $i<$n; $i++){
			unset($array[$i]);	
		}
		
		$min_mean = min($array);
		return $min_mean;
	}
}
?>
